package com.example.com.myapplication.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.com.myapplication.R;
import com.megvii.facetrack.FaceTrackOption;

/**
 * @author by licheng on 2017/7/10.
 */
public class LoadActivity extends Activity implements View.OnClickListener {

    private EditText editText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_load);
        initView();
    }

    private void initView() {
        Button btnNormal = (Button) findViewById(R.id.btn_normal);
        Button btnChoose = (Button) findViewById(R.id.btn_choose);
        Button btnBackCamera = (Button) findViewById(R.id.btn_back_camera);
        Button btnTakePicture = (Button) findViewById(R.id.btn_take_picture);
        Button btnNormalUnAutoStop = (Button) findViewById(R.id.btn_normal_un_auto_stop);
        Button btnSelfResource = (Button) findViewById(R.id.btn_self_resource);
        Button btnRotation = (Button) findViewById(R.id.btn_rotation);
        Button btnSetScore = (Button) findViewById(R.id.btn_set_score);
        editText = (EditText) findViewById(R.id.picture_count);

        btnNormal.setOnClickListener(this);
        btnChoose.setOnClickListener(this);
        btnRotation.setOnClickListener(this);
        btnSetScore.setOnClickListener(this);
        btnBackCamera.setOnClickListener(this);
        btnTakePicture.setOnClickListener(this);
        btnSelfResource.setOnClickListener(this);
        btnNormalUnAutoStop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, MainActivity.class);
        FaceTrackOption.Builder builder = new FaceTrackOption.Builder();
        switch (v.getId()) {
            case R.id.btn_normal:
                // do nothing
                break;
            case R.id.btn_normal_un_auto_stop:
                builder.setEnableAutoStop(false);
                break;
            case R.id.btn_choose:
                if (!TextUtils.isEmpty(editText.getText().toString())) {
                    builder.setFaceTrackCount(Integer.parseInt(editText.getText().toString()));
                } else {
                    builder.setFaceTrackCount(9);
                }
                break;
            case R.id.btn_take_picture:
                builder.setMode(FaceTrackOption.MODE_TAKE_PICTURE);
                break;
            case R.id.btn_back_camera:
                builder.setFrontCamera(false);
                break;
            case R.id.btn_self_resource:
                builder.setResourceId(R.drawable.face);
                builder.setEnableAutoStop(false);
                break;
            case R.id.btn_rotation:
                builder.setRotation(180);
                break;
            case R.id.btn_set_score:
                Intent quality = new Intent(this, QualitySettingActivity.class);
                startActivity(quality);
                return;
            default:
                break;
        }
        FaceTrackOption option = builder.build();
        intent.putExtra(MainActivity.OPTION, option);
        startActivity(intent);
    }
}
